<?php
declare (strict_types=1);

namespace app\shop\command;

use app\shop\library\ShopLogHelper;
use app\shop\service\CouponService;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use Throwable;

class AutoExpireCoupon extends Command
{
    protected function configure(): void
    {
        // 指令配置
        $this->setName('auto_expire_coupon')->setDescription('Auto Expire Coupons');
    }

    protected function execute(Input $input, Output $output): void
    {
        $className = get_class();

        $couponService = new CouponService();

        try {
            $couponService->processUserExpiredCoupon();
            ShopLogHelper::info("自定义命令【 $className 】执行完毕");
        } catch (Throwable $e) {
            ShopLogHelper::error("自定义命令【 $className 】执行失败", ['params' => $input], $e);
        }
    }
}
